package com.niit.agricstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.niit.agricstore.entity.Notice;
import com.niit.agricstore.entity.Product;
import com.niit.agricstore.entity.Type;
import com.niit.agricstore.mapper.TypeMapper;
import com.niit.agricstore.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper,Type> implements TypeService {
    @Autowired
    TypeMapper typeMapper;
    @Override
    public PageInfo<Type> selectAllTypesByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Type> list = typeMapper.selectList(null);
        PageInfo pageInfo = new PageInfo<>(list);
        System.out.println("分页信息"+pageInfo);
        return pageInfo;
    }

    @Override
    public Type getCurrentType(Long id) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type_id",id);
        return typeMapper.selectOne(queryWrapper);
    }

    @Override
    public int deleteType(int typeId) {
        Type type=typeMapper.selectById(typeId);
        return typeMapper.deleteById(type);
    }

    @Override
    public int addTypes(Type type) {
        return typeMapper.addTypes(type);
    }

    @Override
    public Type selectTypeById(Integer typeId) {
        return typeMapper.selectTypeById(typeId);
    }
}

